home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / DialogControls / PatchNewControl.c < prev    next >
C/C++ Source or Header  |  1995-02-02  |  3KB  |  65 lines

  1. #include <PatchNewControl.h>
  2.  
  3. static pascal ControlHandle MyNewControl( WindowPtr theWindow, Rect *ctrlRect, Str255 title, Boolean visible,
  4.                                             short val, short min, short max, short ctrlType, long refCon );
  5.  
  6. typedef pascal ControlHandle (*NewControlProcPtr) ( WindowPtr, Rect*, Str255,
  7. Boolean, short, short, short, short, long );
  8.  
  9. enum {
  10.         uppNewControlProcInfo = kPascalStackBased
  11.                  | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  12.                  | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
  13.                  | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Rect*)))
  14.                  | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(StringPtr)))
  15.                  | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Boolean)))
  16.                  | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short)))
  17.                  | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(short)))
  18.                  | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(short)))
  19.                  | STACK_ROUTINE_PARAMETER(8, SIZE_CODE(sizeof(short)))
  20.                  | STACK_ROUTINE_PARAMETER(9, SIZE_CODE(sizeof(long)))
  21. };
  22.  
  23. #if GENERATINGCFM
  24.         typedef UniversalProcPtr NewControlUPP;
  25.         
  26.         #define CallNewControlProc(userRoutine,w,rect,title,vis,val,min,max,ctrlType,refCon)           \
  27.                         (ControlHandle) CallUniversalProc((UniversalProcPtr)(userRoutine), uppNewControlProcInfo,\
  28.                                                         (w),(rect),(title),(vis),(val),(min),(max),(ctrlType),(refCon))
  29.                                                         
  30.         #define NewNewControlProc(userRoutine)          \
  31.                         (NewControlUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppNewControlProcInfo, GetCurrentISA())
  32. #else
  33.         typedef NewControlProcPtr NewControlUPP;
  34.         
  35.         #define CallNewControlProc(userRoutine,w,rect,title,vis,val,min,max,ctrlType,refCon)   \
  36.             (*(userRoutine))((w),(rect),(title),(vis),(val),(min),(max),(ctrlType),(refCon))
  37.         #define NewNewControlProc(userRoutine)          \
  38.             (NewControlUPP)(userRoutine)
  39. #endif
  40.  
  41. static NewControlUPP sOldNewControl;
  42. static NewControlUPP myNewControlUPP;
  43.  
  44. static pascal ControlHandle MyNewControl( WindowPtr theWindow, Rect *ctrlRect, Str255 title, Boolean visible,
  45.                                             short val, short min, short max, short ctrlType, long refCon )
  46. {
  47.         if( ctrlType==checkBoxProc || ctrlType==radioButProc )
  48.                 ctrlType |= useWFont;                                   // Make check/radio buttons use window's font
  49.         return CallNewControlProc(sOldNewControl, theWindow,ctrlRect,title,visible,val,min,max,ctrlType,refCon);
  50. }
  51.  
  52. void    PatchNewControl( void )
  53. {
  54.  
  55.     myNewControlUPP = NewNewControlProc(&MyNewControl);
  56.  
  57.     sOldNewControl = (NewControlUPP)GetToolboxTrapAddress(_NewControl);
  58.     SetToolboxTrapAddress((UniversalProcPtr)myNewControlUPP,_NewControl);// Patch NewControl
  59. }
  60.  
  61. void    UnPatchNewControl( void )
  62. {
  63.     SetToolboxTrapAddress((UniversalProcPtr)sOldNewControl,_NewControl);
  64.     DisposeRoutineDescriptor(myNewControlUPP);
  65. }